package org.wuzhou.lvyou.view;

import org.wuzhou.lvyou.R;
import org.wuzhou.lvyou.activity.AboutActivity;
import org.wuzhou.lvyou.activity.MainActivity;
import org.wuzhou.lvyou.base.BaseView;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.view.MotionEvent;

public class AboutView extends BaseView {
	
	private AboutActivity father;
	
	private Bitmap bmp_about_bg;
	private Bitmap bmp_btn_bg;
	
	private Bitmap bmp_contact_us_bg;
	private Bitmap bmp_contact_us_bg1;
	private Bitmap bmp_contact_us_bg2;
	private Bitmap bmp_back_bg;
	private Bitmap bmp_back_bg1;
	private Bitmap bmp_back_bg2;
	//
	private RectF rect_about_bg;
	private RectF rect_contact_us_bg;
	private RectF rect_back_bg;


	
	public AboutView(AboutActivity father) {
		super(father);
		this.father=father;
	}

	@Override
	public void initRect() {
		rect_about_bg=new RectF(0,0,screenW,screenH);
		rect_contact_us_bg=new RectF((screenW-bmp_contact_us_bg.getWidth())/2,screenH-50-bmp_contact_us_bg.getHeight(),(screenW+bmp_contact_us_bg.getWidth())/2,screenH-50);
		rect_back_bg=new RectF(-10,-10,bmp_back_bg.getWidth()-10,bmp_back_bg.getHeight()+20);
		
		
		
	}

	@Override
	public void initBimtap() {
		Resources res=getResources();
		bmp_about_bg=BitmapFactory.decodeResource(res, R.drawable.about_bg1);
		bmp_btn_bg=BitmapFactory.decodeResource(res, R.drawable.btn_bg);
		
	
		
		bmp_contact_us_bg1=BitmapFactory.decodeResource(res, R.drawable.contact_us1);
		bmp_contact_us_bg2=BitmapFactory.decodeResource(res, R.drawable.contact_us2);
		bmp_contact_us_bg=bmp_contact_us_bg1;
		
		bmp_back_bg1=BitmapFactory.decodeResource(res, R.drawable.about_word_back);
		bmp_back_bg2=BitmapFactory.decodeResource(res, R.drawable.about_word_back1);
		bmp_back_bg=bmp_back_bg1;
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		canvas.drawBitmap(bmp_about_bg, null, rect_about_bg, null);
		canvas.drawBitmap(bmp_contact_us_bg, null, rect_contact_us_bg, null);
		canvas.drawBitmap(bmp_btn_bg, null, rect_back_bg, null);
		canvas.drawBitmap(bmp_back_bg, null, rect_back_bg, null);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		
		// 获取屏幕坐标
		int _x = (int) event.getX();
		int _y = (int) event.getY();
		if (event.getAction() == MotionEvent.ACTION_DOWN) {

			if (rect_contact_us_bg.contains(_x, _y)) {
				bmp_contact_us_bg = bmp_contact_us_bg2;
			}
			if (rect_back_bg.contains(_x, _y)) {
				bmp_back_bg = bmp_back_bg2;
			}

		} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
			if (!rect_contact_us_bg.contains(_x, _y)) {
				bmp_contact_us_bg = bmp_contact_us_bg1;
			}
			if (!rect_back_bg.contains(_x, _y)) {
				bmp_back_bg = bmp_back_bg1;
			}
			
			
		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			if (rect_contact_us_bg.contains(_x, _y)) {
				bmp_contact_us_bg = bmp_contact_us_bg1;
			}
			if (rect_back_bg.contains(_x, _y)) {
				bmp_back_bg = bmp_back_bg1;
				father.gotoActivity(father, MainActivity.class);
			}
			
		}
		return true;
	}

}
